class Result {
  static SUCCESS_CODE = 200;
  static ERROR_CODE = 500;
  static NOT_FOUND_CODE = 404;
  static BAD_REQUEST_CODE = 400;
  static ACCESS_DENIED_CODE = 403;
  static INVALID_TOKEN_CODE = 403;

  static SUCCESS_MESSAGE = 'Operation successful';
  static Failed_MESSAGE = 'Operation failed';
  static BAD_REQUEST_MESSAGE = 'Request parameter error';
  static NOT_FOUND_MESSAGE = 'Resource not found';
  static INTERNAL_SERVER_ERROR_MESSAGE = 'Internal server error';
  static ACCESS_DENIED_MESSAGE = 'Access denied';
  static INVALID_TOKEN_MESSAGE = 'Invalid token';

  // Return successful response
  static success(res, data, message = Result.SUCCESS_MESSAGE, code = Result.SUCCESS_CODE) {
    return res.status(code).json(new ResultData(data, message, code));
  }

  // Return error response
  static error(res, message = Result.Failed_MESSAGE, code = Result.ERROR_CODE) {
    return res.status(code).json(new ResultData(null, message, code));
  }

  // Return internal server error response
  static internalError(res, message = Result.INTERNAL_SERVER_ERROR_MESSAGE) {
    return this.error(res, message, Result.ERROR_CODE);
  }

  // Return bad request response
  static badRequest(res, message = Result.BAD_REQUEST_MESSAGE) {
    return this.error(res, message, Result.BAD_REQUEST_CODE);
  }

  // Return not found response
  static notFound(res, message = Result.NOT_FOUND_MESSAGE) {
    return this.error(res, message, Result.NOT_FOUND_CODE);
  }
}

export class ResultData {
  constructor(data = null, message = Result.SUCCESS_CODE, code = Result.SUCCESS_CODE) {
    this.code = code;
    this.data = data;
    this.message = message;
    return this;
  }

  static success(data, message = Result.SUCCESS_MESSAGE, code = Result.SUCCESS_CODE) {
    return new ResultData(data, message, code);
  }

  static error(message = Result.Failed_MESSAGE, code = Result.ERROR_CODE) {
    return new ResultData(null, message, code);
  }
}

export default Result;
